package thread.state;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: yield方法的使用
 * @date 2022/10/29 20:55
 */
public class YieldTest {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                System.out.println(Thread.currentThread().getName());
                // 春鹏线程就会让出CPU，进入就绪态，等待被CPU继续调度
                Thread.yield();
            }
        },"春鹏线程");
        t1.start();
        Thread t2 = new Thread(() -> {
            while (true) {
                System.out.println(Thread.currentThread().getName());
            }
        },"云鹏线程");
        t2.start();
    }
}